﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using DBUnitility;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
    public class IPTypeService
    {
        /// <summary>
        /// 获取所有IP类型信息
        /// </summary>
        /// <returns></returns>
        public List<IPType> GetAllIPType()
        {
            string sql = "select IPAddress,IPId,IPName from IPType";
            List<IPType> list = new List<IPType>();
            try
            {
                SqlDataReader objReader = SQLHelper.GetReader(sql);
                while (objReader.Read())
                {
                    list.Add(new IPType() 
                    { 
                        IPAddress = objReader["IPAddress"].ToString(),
                        IPId = Convert.ToInt32(objReader["IPId"]),
                        IPName = objReader["IPName"].ToString()
                    });
                }
                objReader.Close();
                return list;
            }
            catch (Exception ex)
            {
                
                throw new Exception("获取IP类型失败.详细信息：");
            }
        }
        public List<IPType> GetAllIPType(string ipType)
        {
            string sql = "select IPAddress,IPId,IPName from " + ipType;
            
            List<IPType> list = new List<IPType>();
            try
            {
                SqlDataReader objReader = SQLHelper.GetReader(sql);
                while (objReader.Read())
                {
                    list.Add(new IPType()
                    {
                        IPAddress = objReader["IPAddress"].ToString(),
                        IPId = Convert.ToInt32(objReader["IPId"]),
                        IPName = objReader["IPName"].ToString()
                    });
                }
                objReader.Close();
                return list;
            }
            catch (Exception ex)
            {
                throw new Exception("获取IP类型失败.详细信息：");
            }
        }
    }
}
